package cn.kgc.spring.factory;

import org.springframework.beans.factory.FactoryBean;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

/**
 * @author: mosin
 * @version: v1.0  2022/6/30
 * 实现 FactoryBean接口的工厂对象
 * 泛型 指代工厂对象返回值的类型
 */
public class ConnectionInterfaceFactoryBean implements FactoryBean<Connection> {


    @Override
    public Connection getObject() throws Exception {

        Class.forName("com.mysql.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql:///java2215?serverTimezone=UTC", "root", "root");
        return  connection;
    }

    @Override
    public Class<?> getObjectType() {
        return Connection.class;
    }

    //  设置返回的实例化对象的是不单例的
    @Override
    public boolean isSingleton() {  // 返回值是true  表示是单例的bean  false  表示不是单例的bean

        return false;
    }
}
